package com.dean.thread.callable;

import com.dean.service.DeanExecutorService;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadPoolExecutor;

public class TestCallable implements Callable {
    private String id;
    public TestCallable(String id){
        this.id = id;
    }
    @Override
    public Object call() throws Exception {
        System.out.println("发送邮件给:"+id);
        return "成功"+id;
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor executorService = DeanExecutorService.getInstance();
        FutureTask<TestCallable> testCallable = new FutureTask<>(new TestCallable("1"));
        FutureTask<TestCallable> testCallable3 = new FutureTask<>(new TestCallable("3"));
        FutureTask<TestCallable2> testCallable2  = new FutureTask<>(new TestCallable2("2"));
        System.out.println("-----------------------------------------");
        executorService.submit(testCallable);
        executorService.submit(testCallable2);
        executorService.submit(testCallable3);
        System.out.println(testCallable2.get());
        System.out.println(testCallable.get());
        System.out.println(testCallable3.get());

    }


}


class TestCallable2 implements Callable{
    private String id;
    public TestCallable2(String id){
        this.id = id;
    }
    @Override
    public Object call() throws Exception {
        Thread.sleep(2000);
        System.out.println("发送邮件给:"+id);
        return "成功"+id;
    }
}


